package com.nlelpct.security.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nlelpct.model.vo.ResponseResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author :小马
 * @date : 2023-07-12
 */
public class ResponseUtil {
    public static void out(HttpServletResponse response, ResponseResult<String> resultModel)  {
        ObjectMapper objectMapper = new ObjectMapper();
        response.setStatus(HttpStatus.OK.value());
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        try {
            objectMapper.writeValue(response.getOutputStream(), resultModel);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
